package grape.crm.rest.customerbelong.mvc;

import grape.common.rest.mvc.BaseController;
import grape.crm.rest.customerbelong.form.CustomerBelongUpdateForm;
import grape.crm.rest.customerbelong.mapper.CustomerBelongWebMapper;
import grape.crm.rest.customerbelong.vo.CustomerBelongVo;
import grape.crm.service.customerbelong.api.ICustomerBelongService;
import grape.crm.service.customerbelong.po.CustomerBelong;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
/**
 * <p>
 * 客户归属 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-09-14
 */
@RestController
@RequestMapping("/crm/customerbelong")
@Api(tags = "客户归属相关接口")
public class CustomerBelongController extends BaseController<CustomerBelongVo, CustomerBelong> {

    @Autowired
    private CustomerBelongWebMapper currentWebMapper;
    @Autowired
    private ICustomerBelongService currentService;


    @ApiOperation("根据ID查询客户归属")
    @PreAuthorize("hasAuthority('customerbelong:single:queryById')")
    @GetMapping("/{id}")
    @ResponseStatus(HttpStatus.OK)
    public CustomerBelongVo queryById(@PathVariable String id) {
        return super.queryById(id);
    }
     @ApiOperation("删除客户归属")
     @PreAuthorize("hasAuthority('customerbelong:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新客户归属")
     @PreAuthorize("hasAuthority('customerbelong:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public CustomerBelongVo update(@PathVariable String id,@RequestBody @Valid CustomerBelongUpdateForm uf) {
         CustomerBelong po = currentWebMapper.formToPo(uf);
         po.setId(id);
         return super.update(po);
     }


}
